Exercise 25: Mississippi River Mapping

ESS 330 - Quantitative Reasoning

library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats   1.0.0     ✔ readr     2.1.5
✔ ggplot2   3.5.1     ✔ stringr   1.5.1
✔ lubridate 1.9.4     ✔ tibble    3.2.1
✔ purrr     1.0.2     ✔ tidyr     1.3.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(units)
Warning: package 'units' was built under R version 4.4.3
udunits database from C:/Users/Zacha/AppData/Local/R/win-library/4.4/units/share/udunits/udunits2.xml
library(flextable)
Warning: package 'flextable' was built under R version 4.4.3

Attaching package: 'flextable'

The following object is masked from 'package:purrr':

    compose
library(ggplot2)
library(sf)
Warning: package 'sf' was built under R version 4.4.3
Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE
library(AOI)
library(USAboundaries)
library(USAboundariesData)

Attaching package: 'USAboundariesData'

The following object is masked from 'package:AOI':

    zipcodes
eqdc <- '+proj=eqdc +lat_0=40 +lon_0=-96 +lat_1=20 +lat_2=60 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs'

df <- data.frame(name = state.name, 
                X = state.center$x, 
                Y = state.center$y)
df_sf_gcs <- st_as_sf(df, 
                   coords = c("X", "Y"), 
                   crs = 4269)
states_pcs <- st_transform(df_sf_gcs, 5070)
rivers <- read_sf("../data/assignment_data/majorrivers")
MS_rivers <- rivers %>% 
  filter(SYSTEM == "Mississippi")
MS_rivers <- st_as_sfc(MS_rivers, 
                   coords = c("X", "Y"), 
                   crs = 4269)
conus_states <- setdiff(state.abb, c("AK", "HI"))
  all_counties <- us_counties()
names(all_counties) <- make.unique(names(all_counties))
conus_counties <- all_counties %>%
  filter(!(state_abbr %in% c("AK", "HI")))

# counties intersecting MS river system
mississippi_counties <- st_filter(conus_counties, MS_rivers, .predicate = st_intersects)

# plot
us_mississippi_river_plot <- ggplot() +
  geom_sf(data = conus_counties, fill = "grey90", color = "white") +
  geom_sf(data = mississippi_counties, fill = "lightblue", color = "blue") +
  geom_sf(data = MS_rivers, color = "darkblue") +
  labs(title = "Mississippi River Watershed") +
  theme_minimal()

us_mississippi_river_plot